<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>专利下载系统</title>
    <link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
    <link href="{{ url_for('static', filename='css/icons.css') }}" rel="stylesheet">
    <style>
        body {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        .main-container {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 20px;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            backdrop-filter: blur(10px);
            margin: 2rem auto;
            max-width: 1200px;
        }
        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 2rem;
            border-radius: 20px 20px 0 0;
            text-align: center;
        }
        .nav-tabs .nav-link {
            border: none;
            color: #667eea;
            font-weight: 500;
            margin-right: 1rem;
            border-radius: 10px;
        }
        .nav-tabs .nav-link.active {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
        .card {
            border: none;
            border-radius: 15px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
            margin-bottom: 1.5rem;
        }
        .btn-primary {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border: none;
            border-radius: 10px;
            padding: 0.75rem 2rem;
            font-weight: 500;
        }
        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
        }
        .form-control {
            border-radius: 10px;
            border: 2px solid #e9ecef;
            padding: 0.75rem 1rem;
        }
        .form-control:focus {
            border-color: #667eea;
            box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
        }
        .status-badge {
            padding: 0.5rem 1rem;
            border-radius: 20px;
            font-size: 0.875rem;
            font-weight: 500;
        }
        .status-pending { background: #fff3cd; color: #856404; }
        .status-downloading { background: #d1ecf1; color: #0c5460; }
        .status-completed { background: #d4edda; color: #155724; }
        .status-failed { background: #f8d7da; color: #721c24; }
        .file-item {
            background: #f8f9fa;
            border-radius: 10px;
            padding: 1rem;
            margin-bottom: 0.5rem;
            border-left: 4px solid #667eea;
        }
        .loading {
            display: inline-block;
            width: 20px;
            height: 20px;
            border: 3px solid #f3f3f3;
            border-top: 3px solid #667eea;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
</head>
<body>
    <div class="container-fluid">
        <div class="main-container">
            <div class="header">
                <h1><i class="icon-file-pdf"></i> 专利下载系统</h1>
                <p class="mb-0">快速下载中国专利文档</p>
            </div>
            
            <div class="p-4">
                <ul class="nav nav-tabs mb-4" id="mainTabs" role="tablist">
                    <li class="nav-item" role="presentation">
                        <button class="nav-link active" id="download-tab" data-bs-toggle="tab" data-bs-target="#download" type="button" role="tab">
                            <i class="icon-download"></i> 专利下载
                        </button>
                    </li>
                    <li class="nav-item" role="presentation">
                        <button class="nav-link" id="search-tab" data-bs-toggle="tab" data-bs-target="#search" type="button" role="tab">
                            <i class="icon-search"></i> 专利搜索
                        </button>
                    </li>
                    <li class="nav-item" role="presentation">
                        <button class="nav-link" id="files-tab" data-bs-toggle="tab" data-bs-target="#files" type="button" role="tab">
                            <i class="icon-folder"></i> 已下载文件
                        </button>
                    </li>
                </ul>
                
                <div class="tab-content" id="mainTabContent">
                    <!-- 专利下载标签页 -->
                    <div class="tab-pane fade show active" id="download" role="tabpanel">
                        <div class="card">
                            <div class="card-body">
                                <h5 class="card-title"><i class="icon-download"></i> 专利下载</h5>
                                <form id="downloadForm">
                                    <div class="mb-3">
                                        <label for="patentNo" class="form-label">专利号</label>
                                        <input type="text" class="form-control" id="patentNo" placeholder="请输入专利号，如：CN202311303481.9">
                                        <div class="form-text">支持格式：CN202311303481.9 或 202311303481.9</div>
                                    </div>
                                    <button type="submit" class="btn btn-primary">
                                        <i class="icon-download"></i> 开始下载
                                    </button>
                                </form>
                                
                                <div id="downloadStatus" class="mt-4" style="display: none;">
                                    <h6>下载状态</h6>
                                    <div id="statusContent"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- 专利搜索标签页 -->
                    <div class="tab-pane fade" id="search" role="tabpanel">
                        <div class="card">
                            <div class="card-body">
                                <h5 class="card-title"><i class="icon-search"></i> 专利搜索</h5>
                                <form id="searchForm">
                                    <div class="row">
                                        <div class="col-md-8">
                                            <div class="mb-3">
                                                <label for="keywords" class="form-label">搜索关键词</label>
                                                <input type="text" class="form-control" id="keywords" placeholder="请输入搜索关键词">
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="mb-3">
                                                <label for="page" class="form-label">页码</label>
                                                <input type="number" class="form-control" id="page" value="1" min="1">
                                            </div>
                                        </div>
                                    </div>
                                    <button type="submit" class="btn btn-primary">
                                        <i class="icon-search"></i> 搜索专利
                                    </button>
                                </form>
                                
                                <div id="searchResults" class="mt-4" style="display: none;">
                                    <h6>搜索结果</h6>
                                    <div id="resultsContent"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- 已下载文件标签页 -->
                    <div class="tab-pane fade" id="files" role="tabpanel">
                        <div class="card">
                            <div class="card-body">
                                <div class="d-flex justify-content-between align-items-center mb-3">
                                    <h5 class="card-title mb-0"><i class="icon-folder"></i> 已下载文件</h5>
                                    <button class="btn btn-outline-primary" onclick="loadFiles()">
                                        <i class="icon-refresh"></i> 刷新
                                    </button>
                                </div>
                                <div id="filesList"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="{{ url_for('static', filename='js/app.js') }}"></script>
    
    <!-- 验证码模态框容器 -->
    <div id="captchaModalContainer"></div>
</body>
</html>